<%--
  Created by IntelliJ IDEA.
  User: ttxs
  Date: 2023/7/17
  Time: 14:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <script src="${pageContext.request.contextPath}/statics/js/jquery.min.js"></script>
  <script>
    function doPage(pageNo) {
      document.forms[0].pageNo.value = pageNo;
      document.forms[0].submit();
    }
  </script>
  <body>
  <jsp:include page="/WEB-INF/jsp/header.jsp"/>
  <h1>用户列表</h1>
  <c:if test="${sessionScope.loginUser == null}">
    <a href="${pageContext.request.contextPath}/users/login">登录</a>
  </c:if>
  <c:if test="${sessionScope.loginUser != null}">
    <p>欢迎你，${sessionScope.loginUser.realName}</p>
    <a href="${pageContext.request.contextPath}/users/logout">注销</a>
  </c:if>
  <div>${msg}</div>
  <a href="${pageContext.request.contextPath}/users/add">添加</a>
  <form action="${pageContext.request.contextPath}/roles/list" method="post">
<%--    <input name="pageNo" type="hidden"/>--%>
  code:<input name="code" value="${role.code}"/>
  roleName:<input name="roleName" value="${role.roleName}"/>
    <input type="submit" value="查询">
  <table>
    <tr>
      <td>ID</td>
      <td>code</td>
      <td>roleName</td>
      <td>操作</td>
    </tr>
    <c:forEach var="item" items="${page.list}" varStatus="i">

    <tr <c:if test="${i.count%2==0}">style="background-color: antiquewhite"</c:if>>
      <td>${item.id}</td>
      <td>${item.code}</td>
      <td>${item.roleName}</td>
      <td>
        <a href="javascript:del(${item.id})" onclick="return confirm('确定删除吗？')">ajax删除</a>
        <a href="${pageContext.request.contextPath}/roles/toRestUpdate/${item.id}">rest修改</a>
      </td>
    </tr>
    </c:forEach>
  </table>
  <div>
    当前${page.pageNum}/${page.pages}页，共${page.total}条，每页<input onchange="doPage(${page.pageNum})" size="2" name="pageSize" value="${page.pageSize}">条
  </div>
    <div>
      <a href="javascript:void(0)" onclick="doPage(1)">首页</a>
      <a href="javascript:void(0)" onclick="doPage(${page.pageNum - 1})">上页</a>
      <a href="javascript:void(0)" onclick="doPage(${page.pageNum + 1})">下页</a>
      <a href="javascript:void(0)" onclick="doPage(${page.pages})">尾页</a>

      <select name="pageNo" onchange="doPage(this.value)">
        <c:forEach var="i"  begin="1" end="${page.pages}">
          <option <c:if test="${i ==page.pageNum}">selected</c:if> value="${i}">${i}</option>
        </c:forEach>
      </select>
      <c:forEach var="i" begin="1" end="${page.pages}">
        <a href="javascript:void(0)" <c:if test="${i ==page.pageNum}">style="color: red"</c:if>  onclick="doPage(${i})"> ${i}</a>
      </c:forEach>
    </div>
    <div id="userInfo"></div>
  </form>
  </body>
</html>
